// 引用sdk
import config from '../config/config.js'

import SMSClient from '@alicloud/sms-sdk'


export default class SMSService {
  constructor() {
    this.smsClient = new SMSClient({
      accessKeyId: config.accessKeyId,
      secretAccessKey: config.secretAccessKey
    })
  }

  async send (phone, username, pwd) {
    let data = {
      username: username,
      pwd: pwd
    }
    let s = await this.smsClient.sendSMS({
      PhoneNumbers: phone,
      SignName: config.signName,
      TemplateCode: 'SMS_463160430',
      TemplateParam: JSON.stringify(data)
    })

    if (s.Code == 'OK') {
      return true
    }
    else {
      logger.error('错误码：' + s.Code);
      return false
    }
  }
}